#include"gui.h"
#include"gui_window.h"
#include"gui_event.h"
#include<stdio.h>
#include<stdlib.h>
#include"fm_window.h"
#include"gui_list.h"
#include<assert.h>

gui_spirit_t *fm_window; //main window
gui_surface_t *fm_surface; //widnow surface

int fm_window_init()
{
    if(gui_init(NULL,NULL)<0)
    {
        dprintf("[gui] init gui error\n");
        return -1;
    }
    
    fm_window=gui_window_create_simple(FM_APP_NAME,0,0,FM_DEFAULT_WIDTH,FM_DEFAULT_HEIGHT);
    if(!fm_window)
    {
        dprintf("[fm] create window failed\n");
        return -1;
    }
    gui_spirit_show(fm_window);

    //rectfill background
    fm_surface=fm_window->surface;
    assert(fm_surface);
    fm_window_rectfill(0,0,fm_surface->w,fm_surface->h,FM_WINDOW_BACKCOLOR);
    
    //create list 
    fm_list_create(fm_surface->h/20,fm_surface->w,fm_surface->h);
    //create func area
    fm_func_create(fm_surface->w,20);
    
    return 0;
}

void fm_window_update(int x,int y,int width,int height)
{
    gui_window_update(GUI_WINDOW(fm_window),x,y,width,height);
}


void fm_window_clear()
{
    gui_surface_rectfill(fm_surface,0,0,fm_surface->w,fm_surface->h,FM_WINDOW_BACKCOLOR);
    gui_window_update(GUI_WINDOW(fm_window),0,0,fm_surface->w,fm_surface->h);
}

void fm_window_rectfill(int x,int y,int width,int height)
{
    gui_surface_rectfill(fm_surface,x,y,width,height,FM_WINDOW_BACKCOLOR);
    gui_window_update(GUI_WINDOW(fm_window),x,y,width,height);
}

